import {useBaseInfoStore} from "@/store/modules/base-info";
import api from "@/api";

/**
 * 页面锁相关
 */
export default {
  created() {
    this.timer = null;
    //添加页面的心跳锁
    this.activeLock();
  },
  beforeDestroy() {
    this.timer && clearTimeout(this.timer);
  },
  methods: {
    activeLock() {
      //不是处理不用添加
      const {affair, summary} = useBaseInfoStore().baseInfo?.businessData || {};
      if (affair.state !== 3 && affair.subState !== 16) {
        return;
      }
      const {
        id: summaryId,
        processId,
      } = summary || {};
      //协同更新查看时间的参数
      const {
        id: affairId,
        formRecordid: formMasterId,
      } = affair || {};
      const params = {
        formMasterId,
        processId,
        affairId,
        summaryId,
        loginPlatform: 'pc'
      }
      this.fn=()=>{
        //添加协同心跳锁 30s发送一次
        this.timer = setTimeout(() => {
          clearTimeout(this.timer);
          api.commonActiveLock(JSON.stringify(params));
          this.fn();
        }, 30 * 1000);
      };
      this.fn();
      
    }
  }
}